// index.module.less
// 全局样式重置
html, body, #root {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  background-color: #f5f5f5;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  .title {
    text-align: center;
    margin: 0;
    padding: 16px;
    color: #333;
    font-size: 20px;
    font-weight: 600;
    background-color: #fff;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }

  .chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #fff;
    position: relative;
  }

  .chatBox {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    // 为iOS设备优化滚动
    -webkit-overflow-scrolling: touch;
    // 底部留出空间，防止被输入框遮挡
    padding-bottom: 80px;
  }

  .message {
    display: flex;
    max-width: 80%;
    
    &.user {
      align-self: flex-end;
      
      .messageContent {
        background-color: #1890ff;
        color: white;
        border-radius: 18px 18px 4px 18px;
      }
    }
    
    &.assistant {
      align-self: flex-start;
      
      .messageContent {
        background-color: #f0f0f0;
        color: #333;
        border-radius: 18px 18px 18px 4px;
      }
    }
  }

  .messageContent {
    padding: 12px 16px;
    word-break: break-word;
    line-height: 1.5;
  }

  .typingIndicator {
    display: flex;
    align-items: center;
    height: 20px;
    
    span {
      height: 8px;
      width: 8px;
      background-color: #999;
      border-radius: 50%;
      display: inline-block;
      margin: 0 2px;
      animation: typing 1.4s infinite both;
      
      &:nth-child(2) {
        animation-delay: 0.2s;
      }
      
      &:nth-child(3) {
        animation-delay: 0.4s;
      }
    }
  }

  .scrollAnchor {
    height: 1px;
  }

  .inputArea {
    padding: 16px;
    background-color: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    // 添加阴影，使其与内容区分开
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    // 确保在内容之上
    z-index: 5;
    // 上移输入框，避免被导航栏遮挡
    margin-bottom: 40px;
  }

  .inputContainer {
    display: flex;
    gap: 12px;
    
    input {
      flex: 1;
      height: 44px;
      border: 1px solid #ddd;
      border-radius: 22px;
      padding: 0 16px;
      font-size: 16px;
      outline: none;
      transition: border-color 0.3s;
      
      &:focus {
        border-color: #1890ff;
      }
      
      &:disabled {
        background-color: #f5f5f5;
        cursor: not-allowed;
      }
    }
  }

  .sendButton {
    height: 44px;
    padding: 0 20px;
    border: none;
    border-radius: 22px;
    background-color: #1890ff;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s;
    white-space: nowrap;
    flex-shrink: 0;
    
    &:hover:not(:disabled) {
      background-color: #40a9ff;
    }
    
    &:disabled {
      background-color: #ccc;
      cursor: not-allowed;
    }
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-5px);
  }
}

/* 移动设备适配 - 防止底部导航栏遮挡 */
@media (max-width: 768px) {
  .container {
    // 为移动设备添加安全区域插入
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  
  .chatBox {
    padding: 12px;
    // 增加底部内边距，为输入框留出更多空间
    padding-bottom: 90px;
  }
  
  .inputArea {
    padding: 12px;
    // 增加底部外边距，避免被导航栏遮挡
    margin-bottom: 30px;
    // 使用安全区域插入
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  
  .message {
    max-width: 90%;
  }
  
  // 针对有底部导航栏的设备进一步调整
  @media (max-height: 700px) {
    .chatBox {
      padding-bottom: 80px;
    }
    
    .inputArea {
      margin-bottom: 40px;
      padding: 10px;
      padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
  }
}

/* 防止移动端浏览器地址栏和工具栏影响布局 */
@media (max-height: 700px) {
  .container {
    height: 100%;
    min-height: 100%;
  }
}

/* 特别针对iPhone等有底部导航栏的设备 */
.has-bottom-navbar {
  .inputArea {
    margin-bottom: 60px !important;
  }
  
  .chatBox {
    padding-bottom: 100px !important;
  }
}